import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

declare module 'vue-router' {
    // 定义原信息类型
    interface RouteMeta {
        title: string
    }
}
const routes: Array<RouteRecordRaw> = [
    {
        path: "/",
        component: () => import('../components/RouterFooter.vue'),
        meta: {
            title: "主页"
        },
        // 路由重定向
        /* redirect:"/Login"
        redirect: to => {
            return {
                path: "/Login",
                query: {
                    name: 'x'
                }
            }
        }, */
        // 路由起名 全部指向"/"
        alias: ['/root', '/root1'],
        children: [
            {
                // 默认展示设置为空
                path: "",
                component: () => import('../components/RouterBody.vue')
            },
            {
                path: "/Login",
                name: "Login",
                component: () => import('../components/RouterBody.vue')
            },
        ]
    },
    {
        path: "/Login",
        name: "Login",
        component: {
            Login: () => import('../components/Routerrrr.vue')
        }
    },
    {
        path: "/Login/:id",
        name: "Login2",
        component: () => import('../components/Routerrrr.vue')
    },

    // 导航守卫
    {
        path: "/X",
        name: "X",
        component: () => import('../components/views/Login.vue'),
        meta: {
            title: "用户表单提交",
            transition: "animate_fadeIn"
        },
    },
    {
        path: "/X2",
        name: "X2",
        component: () => import('../components/views/Index.vue'),
        meta: {
            title: "主页",
            transition: "animate_fadeIn"
        },
    }

]
const router = createRouter({
    history: createWebHistory(),
    scrollBehavior: (to, from, savePosition) => {
        console.log(savePosition);
        // 确保页面切换时保持上次滚动位置
        if (savePosition) {
            return savePosition
        } else {
            return {
                top: 0
            }
        }

    },
    routes
})

export default router